﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Marmat.Forms.Views.DataGrid
{
    public class SaveProjectColumn
    {

        /// <summary>
        /// 前台表对应的列
        /// </summary>
        public string ViewColumn { get; set; }

        /// <summary>
        /// 后台表对应的列
        /// </summary>       
        [DefaultValue(null)]
        public string DataColumn
        {
            get => this._DataColumn;
            set => this._DataColumn = value;
        }
        private string _DataColumn;

        public void ResetViewColumn()
        {
            this.ViewColumn = null;
        }
        protected bool ShouldSerializeViewColumn()
        {
            return !(this.ViewColumn == "");
        }

        protected void ResetDataColumn()
        {
            this.DataColumn = string.Empty;
        }
        protected bool ShouldSerializeDataColumn()
        {
            return !(string.IsNullOrEmpty(this._DataColumn));
        }

        public override string ToString()
        {
            string result = base.ToString();
            if (!string.IsNullOrEmpty(this.ViewColumn))
                result = $@"ViewColumn=""{this.ViewColumn}""";
            if (!string.IsNullOrEmpty(this._DataColumn))
                result += string.IsNullOrEmpty(result) ? "" : "," + $@"DataColumn=""{this.DataColumn}""";
            return result;
        }
    }
}